<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->

        <label class="el-form-item-label">标签1</label>
        <!--        <el-input v-model="query.tag1" clearable placeholder="标签1" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />-->
        <el-select v-model="query.tag1" filterable placeholder="请选择" clearable>
          <el-option
            v-for="item in dict.eos_tag_1"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <label class="el-form-item-label">标签2</label>
        <!--        <el-input v-model="query.tag2" clearable placeholder="标签2" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />-->
        <el-select v-model="query.tag2" filterable placeholder="请选择" clearable>
          <el-option
            v-for="item in dict.eos_tag_2"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <label class="el-form-item-label">标签3</label>
        <!--        <el-input v-model="query.tag3" clearable placeholder="标签3" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />-->
        <el-select v-model="query.tag3" filterable placeholder="请选择" clearable>
          <el-option
            v-for="item in dict.eos_tag_3"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <label class="el-form-item-label">知识主题</label>
        <el-input v-model="query.knowledgeTopic" clearable placeholder="知识主题" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">审核状态</label>
        <!--        <el-input v-model="query.approvalStatus" clearable placeholder="审核状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" clearable/>-->
        <el-select v-model="query.approvalStatus" filterable placeholder="请选择" clearable>
          <el-option
            v-for="item in dict.approval_status"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <label class="el-form-item-label">修改时间</label>
        <date-range-picker
          v-model="query.updatedAt"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          class="date-item"
        />
        <!--        <label class="el-form-item-label">知识切片(初始版)</label>
        <el-input v-model="query.knowledgeSliceInitial" clearable placeholder="知识切片(初始版)" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">记录状态 (0: 不可用, 1: 可用)</label>
        <el-input v-model="query.recordStatus" clearable placeholder="记录状态 (0: 不可用, 1: 可用)" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <date-range-picker
          v-model="query.createdAt"
          start-placeholder="createdAtStart"
          end-placeholder="createdAtStart"
          class="date-item"
        />
        -->
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <!--      <crudOperation :permission="permission" />-->
      <crudOperation :permission="permission">
        <el-button
          v-if="crud.optShow.edit"
          slot="left"
          v-permission="permission.approve"
          class="filter-item"
          size="mini"
          type="success"
          icon="el-icon-edit"
          :disabled="crud.selections.length !== 1"
          @click="approve"
        >
          审核
        </el-button>
      </crudOperation>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <!--          <el-form-item label="业务空间ID">
            <el-input v-model="form.businessSpaceId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="类目ID">
            <el-input v-model="form.categoryId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="处理状态">
            <el-input v-model="form.processState" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="文件类型">
            <el-input v-model="form.fileType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="文件行索引">
            <el-input v-model="form.fileIndex" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="文档版本号">
            <el-input v-model="form.fileVersion" style="width: 370px;" />
          </el-form-item>-->

          <el-form-item label="标签1" prop="tag1">
            <el-select v-model="form.tag1" filterable placeholder="请选择" clearable>
              <el-option
                v-for="item in dict.eos_tag_1"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="标签2" prop="tag2">
            <el-select v-model="form.tag2" filterable placeholder="请选择" clearable>
              <el-option
                v-for="item in dict.eos_tag_2"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="标签3" prop="tag3">
            <el-select v-model="form.tag3" filterable placeholder="请选择" clearable>
              <el-option
                v-for="item in dict.eos_tag_3"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="知识主题" prop="knowledgeTopic">
            <el-input v-model="form.knowledgeTopic" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="知识切片" prop="knowledgeSliceInitial">
            <el-input v-model="form.knowledgeSliceInitial" :rows="15" type="textarea" style="width: 370px;" />
          </el-form-item>
          <!--          <el-form-item label="知识切片(最终版)">-->
          <!--            <el-input v-model="form.knowledgeSliceFinal" style="width: 370px;" readonly placeholder="录入初始版后，由系统自动生成" />-->
          <!--          </el-form-item>-->
          <el-form-item label="图片">
            <el-input v-model="form.metadataImage" style="width: 370px;" :rows="2" type="textarea" />
          </el-form-item>
          <el-form-item label="响应方式">
            <el-input v-model="form.metadataResponseMethod" style="width: 370px;" :rows="2" type="textarea" />
          </el-form-item>
          <el-form-item label="槽位依赖">
            <el-input v-model="form.metadataSlotDependency" style="width: 370px;" :rows="2" type="textarea" />
          </el-form-item>
          <el-form-item label="调用工具">
            <el-input v-model="form.metadataToolInvocation" style="width: 370px;" :rows="2" type="textarea" />
          </el-form-item>
          <el-form-item v-if="checkPer(['admin','eosSystemFunctionDescription:approve'])" label="审核状态">
            <el-select v-model="form.approvalStatus" filterable placeholder="请选择" clearable>
              <el-option
                v-for="item in dict.approval_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
            <el-input v-model="form.optCodes" style="width: 370px;display: none" />
          </el-form-item>
          <el-form-item v-if="checkPer(['admin','eosSystemFunctionDescription:approve'])" label="审核备注">
            <el-input v-model="form.approvalDesc" style="width: 370px;" :rows="3" type="textarea" />
          </el-form-item>
          <!--  <el-form-item label="经办人">
              <el-input v-model="form.operatorUserId" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="审核人">
              <el-input v-model="form.approvalUserId" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="记录创建时间">
              <el-date-picker v-model="form.createdAt" type="datetime" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="记录修改时间">
              <el-date-picker v-model="form.updatedAt" type="datetime" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="记录状态 (0: 不可用, 1: 可用)">
              <el-select v-model="form.recordStatus" filterable placeholder="请选择">
                <el-option
                  v-for="item in dict.record_status"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>-->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <!--        <el-table-column prop="businessSpaceId" label="业务空间ID" />
        <el-table-column prop="categoryId" label="类目ID" />
        <el-table-column prop="processState" label="处理状态" />
        <el-table-column prop="fileType" label="文件类型" />
        <el-table-column prop="fileIndex" label="文件行索引" />
        <el-table-column prop="fileVersion" label="文档版本号" />-->

        <el-table-column prop="tag1" label="标签1" width="100">
          <template slot-scope="scope">
            {{ dict.label.eos_tag_1[scope.row.tag1] }}
          </template>
        </el-table-column>
        <el-table-column prop="tag2" label="标签2" width="120">
          <template slot-scope="scope">
            {{ dict.label.eos_tag_2[scope.row.tag2] }}
          </template>
        </el-table-column>
        <el-table-column prop="tag3" label="标签3" width="150">
          <template slot-scope="scope">
            {{ dict.label.eos_tag_3[scope.row.tag3] }}
          </template>
        </el-table-column>
        <el-table-column prop="knowledgeTopic" label="知识主题" width="250" />
        <el-table-column prop="knowledgeSliceInitial" label="知识切片" show-overflow-tooltip="true" width="150" />
        <!--        <el-table-column prop="knowledgeSliceFinal" label="知识切片(最终版)" show-overflow-tooltip="true" width="150"/>-->
        <el-table-column prop="metadataImage" label="图片" show-overflow-tooltip="true" width="150" />
        <el-table-column prop="metadataResponseMethod" label="响应方式" show-overflow-tooltip="true" width="150" />
        <el-table-column prop="metadataSlotDependency" label="槽位依赖" show-overflow-tooltip="true" width="150" />
        <el-table-column prop="metadataToolInvocation" label="调用工具" show-overflow-tooltip="true" width="150" />
        <el-table-column prop="approvalStatus" label="审核状态" width="150">
          <template slot-scope="scope">
            {{ dict.label.approval_status[scope.row.approvalStatus] }}
          </template>
        </el-table-column>
        <el-table-column prop="approvalDesc" label="审核备注" show-overflow-tooltip="false" width="150" />
        <el-table-column prop="processState" label="同步知识库状态" width="150">
          <template slot-scope="scope">
            {{ dict.label.process_state[scope.row.processState] }}
          </template>
        </el-table-column>

        <!--        <el-table-column prop="operatorUserId" label="经办人" />-->
        <!--        <el-table-column prop="approvalUserId" label="审核人" />-->
        <el-table-column prop="createdAt" label="记录创建时间" width="150" />
        <el-table-column prop="updatedAt" label="记录修改时间" width="150" />
        <el-table-column v-if="checkPer(['admin','eosSystemFunctionDescription:edit','eosSystemFunctionDescription:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudEosSystemFunctionDescription from '@/api/eosSystemFunctionDescription'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker'

const defaultForm = { id: null, businessSpaceId: null, categoryId: null, processState: null, fileType: null, fileIndex: null, fileVersion: null, approvalStatus: null, approvalDesc: null, operatorUserId: null, approvalUserId: null, tag1: null, tag2: null, tag3: null, knowledgeTopic: null, knowledgeSliceInitial: null, knowledgeSliceFinal: null, metadataImage: null, metadataResponseMethod: null, metadataSlotDependency: null, metadataToolInvocation: null, createdAt: null, updatedAt: null, recordStatus: null, optCodes: null }
export default {
  name: 'EosSystemFunctionDescription',
  components: { pagination, crudOperation, rrOperation, udOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['approval_status', 'eos_tag_1', 'eos_tag_2', 'eos_tag_3', 'record_status', 'process_state'],
  cruds() {
    return CRUD({ title: 'Eos系统功能使用说明', url: 'api/eosSystemFunctionDescription', idField: 'id', sort: 'id,desc', crudMethod: { ...crudEosSystemFunctionDescription }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'eosSystemFunctionDescription:add'],
        edit: ['admin', 'eosSystemFunctionDescription:edit'],
        del: ['admin', 'eosSystemFunctionDescription:del'],
        approve: ['admin', 'eosSystemFunctionDescription:approve']
      },
      rules: {
        tag1: [
          { required: true, message: '标签1不能为空', trigger: 'blur' }
        ],
        tag2: [
          { required: true, message: '标签2不能为空', trigger: 'blur' }
        ],
        tag3: [
          { required: true, message: '标签3不能为空', trigger: 'blur' }
        ],
        knowledgeTopic: [
          { required: true, message: '知识主题不能为空', trigger: 'blur' }
        ],
        knowledgeSliceInitial: [
          { required: true, message: '知识切片(初始版)不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'approvalStatus', display_name: '审核状态' },
        { key: 'tag1', display_name: '标签1' },
        { key: 'tag2', display_name: '标签2' },
        { key: 'tag3', display_name: '标签3' },
        { key: 'knowledgeTopic', display_name: '知识主题' },
        { key: 'knowledgeSliceInitial', display_name: '知识切片(初始版)' },
        { key: 'recordStatus', display_name: '记录状态 (0: 不可用, 1: 可用)' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    approve() {
      console.log(' ### test approve')
      this.form.optCodes = 'approve'
      this.crud.toEdit(this.crud.selections[0])
      // console.log(data)
      // this.crud.toEdit(data)
      // console.log(' ### test approve[approvalStatus] = ' + this.form.approvalStatus)
      // console.log(' ### test approve[currentRow] = ' + this.currentRow)
      // crud.toEdit(crud.selections[0])
    }
  }
}
</script>

<style scoped>

</style>
